using UnityEngine;

public class Bus : MonoBehaviour
{
	public Animator animator;

	public Rigidbody2D rb;

	public AudioSource audioSource;

	public AudioClip crashAudioClip;

	public Transform[] wheels;

	private void FixedUpdate()
	{
		if (rb.velocity.x != 0f)
		{
			Transform[] array = wheels;
			for (int i = 0; i < array.Length; i++)
			{
				array[i].Rotate(0f, 0f, (0f - rb.velocity.x * 10f) / 60f * 360f * Time.deltaTime);
			}
		}
	}

	private void OnTriggerEnter2D(Collider2D collision)
	{
		if (!(collision.gameObject.tag == "Body"))
		{
			return;
		}
		Body body = collision.gameObject.GetComponent<BodyPart>().body;
		body.Die();
		Vector3 normalized = (body.transform.position - base.transform.position).normalized;
		BodyPart[] bodyParts = body.bodyParts;
		foreach (BodyPart bodyPart in bodyParts)
		{
			if (!bodyPart)
			{
				break;
			}
			if (bodyPart.name == "ChestRb")
			{
				bodyPart.rb.AddForce(500f * normalized);
			}
			bodyPart.Bleed(bodyPart.transform.position);
		}
		audioSource.PlayOneShot(crashAudioClip);
	}
}
